<?php

use Faker\Factory as Faker;
use App\Models\Goods;
use App\Repositories\GoodsRepository;

trait MakeGoodsTrait
{
    /**
     * Create fake instance of Goods and save it in database
     *
     * @param array $goodsFields
     * @return Goods
     */
    public function makeGoods($goodsFields = [])
    {
        /** @var GoodsRepository $goodsRepo */
        $goodsRepo = App::make(GoodsRepository::class);
        $theme = $this->fakeGoodsData($goodsFields);
        return $goodsRepo->create($theme);
    }

    /**
     * Get fake instance of Goods
     *
     * @param array $goodsFields
     * @return Goods
     */
    public function fakeGoods($goodsFields = [])
    {
        return new Goods($this->fakeGoodsData($goodsFields));
    }

    /**
     * Get fake data of Goods
     *
     * @param array $postFields
     * @return array
     */
    public function fakeGoodsData($goodsFields = [])
    {
        $fake = Faker::create();

        return array_merge([
            'sn' => $fake->word,
            'name' => $fake->word,
            'click_count' => $fake->randomDigitNotNull,
            'sales_count' => $fake->randomDigitNotNull,
            'brand' => $fake->word,
            'provider_name' => $fake->word,
            'number' => $fake->randomDigitNotNull,
            'market_price' => $fake->word,
            'sale_price' => $fake->word,
            'unit' => $fake->word,
            'sale_start_date' => $fake->word,
            'sale_end_date' => $fake->word,
            'is_on_sale' => $fake->randomDigitNotNull,
            'is_best' => $fake->randomDigitNotNull,
            'is_new' => $fake->randomDigitNotNull,
            'is_hot' => $fake->randomDigitNotNull,
            'sort' => $fake->randomDigitNotNull,
            'desc' => $fake->text,
            'image' => $fake->text,
            'created_at' => $fake->word,
            'updated_at' => $fake->word
        ], $goodsFields);
    }
}
